package sol.leetcode;

import def.ListNode;
import utils.LinkedListUtils;

/**
 * 203. Remove Linked List Elements
 */
public class Issue203 {
    public static ListNode removeElements(ListNode head, int val) {
        if (head == null)
            return null;
        ListNode sub = removeElements(head.next, val);
        if (head.val == val)
            return sub;
        else {
            head.next = sub;
            return head;
        }
    }

    public static void main(String[] args) {
        ListNode head = LinkedListUtils.create(1, 2, 4, 6, 4, 3);
        LinkedListUtils.print(head);

        LinkedListUtils.print(removeElements(head, 4));
    }
}
